package workspace.teaweb.base.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

@Configuration
public class ThreadPoolConfig {
    @Bean("taskExecutor1")
    public ExecutorService taskExecutor() {
        return new ThreadPoolExecutor(
                5, // 核心线程数
                10, // 最大线程数
                60, TimeUnit.SECONDS, // 空闲线程存活时间
                new LinkedBlockingQueue<>(100), // 任务队列容量
                Executors.defaultThreadFactory(),// 线程工厂
                new ThreadPoolExecutor.CallerRunsPolicy() // 拒绝策略：由提交任务的线程直接执行
        );
    }
}
